Skip to content

Fix critical bugs in controller/services/state/CLI, add EventBus thread-safety, and add tests for services/effects/factory#174

Merged
Einswilli merged 5 commits intomasterfrom
fix.cli_new_project
Mar 29, 2026
Merged

Fix critical bugs in controller/services/state/CLI, add EventBus thread-safety, and add tests for services/effects/factory#174
Einswilli merged 5 commits intomasterfrom
fix.cli_new_project

Conversation

@Einswilli
Copy link
Copy Markdown
Contributor

Summary

This PR addresses several critical bugs and memory leaks in the FletX framework, adds thread-safety to core components, and introduces test coverage for previously untested modules (services, effects, factory). The changes improve stability, prevent crashes, and ensure proper resource cleanup.

Changes

Bug Fixes (High Priority)

  1. Controller Event Loop Typo (fletx/core/controller.py:165)

    • Fixed get_event_loop.create_taskget_event_loop().create_task to prevent AttributeError when emitting async events via EventBus.once().
  2. Controller State Comparison (fletx/core/controller.py:419)

    • Fixed self._state != ControllerState.INITIALIZEDself._state.value != to correctly compare the reactive state's value with the enum, enabling controllers to reach the READY state.
  3. Service State Listener Signature (fletx/core/services.py:158-161)

    • Changed on_state_changed(self, state: ServiceState)on_state_changed(self) to match the listener callback (which passes 0 arguments), preventing TypeError when state changes occur.
  4. Computed Property Observer Leak (fletx/core/state.py)

    • Added _dep_observers list to track dependency observers in Computed.
    • Fixed _update_value() to properly dispose of old observers before creating new ones.
    • Updated dispose() to clean up dependency observers.
  5. DI Container Memory Leak (fletx/core/controller.py:448-451)

    • Added DI.delete() calls in FletXController.dispose() to remove controller and effect manager instances from the DI container, preventing memory leaks.
  6. EventBus Thread-Safety (fletx/core/controller.py)

    • Added threading.RLock to EventBus to protect concurrent access to _listeners, _once_listeners, _event_history, and _last_event during emit() and off() operations.
    • Wrapped critical sections in emit() and off() with with self._lock.
  7. CLI String Formatting (fletx/cli/commands/newproject.py:204-206)

    • Fixed malformed f-strings: "\{'='*50}\""=" * 50 to correctly display separators in project creation output.

New Test Coverage (Medium Priority)

Added comprehensive unit tests for:

  • Services (tests/test_services.py): Service state transitions, data handling, disposal, and error management.
  • Effects (tests/test_effects.py): Effect registration, dependency tracking, cleanup behavior, and conditional execution.
  • Factory (tests/test_factory.py): Widget registration, duplicate prevention, method validation, and register_all functionality.

Impact

  • Eliminates crash risks in async event handling.
  • Fixes core lifecycle logic preventing controllers from initializing properly.
  • Resolves memory leaks in DI container and reactive computations.
  • Ensures thread-safe operation in multi-threaded async environments.
  • Adds regression prevention for core services, effects, and factory components.
  • Corrects CLI output formatting for better user experience.

All existing tests continue to pass, and the new tests validate the fixed behaviors.

Checklist

  • Code follows project style and conventions
  • Changes are thoroughly tested (existing + new tests)
  • Documentation/docstrings updated where necessary
  • No breaking changes to public API
  • Backward compatible

Copy link
Copy Markdown
Contributor

@Wgoeh Wgoeh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job thanks 👍🏾

@Einswilli Einswilli merged commit 751e47d into master Mar 29, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants